﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Globalization;
using System.Threading;
using System.Resources;
using System.Net.Configuration;
using System.Collections.Generic;
using DataAccess.DataObject;

namespace EnmineKaitlin
{
    public partial class Home : Common.PageBase
    {        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["LangID"].ToString() == "vi-VN") {
                    rptBanner.DataSource = _BPost.Get(Banner_PostID);
                    rptBanner.DataBind();
                    rptGioiThieu.DataSource = _BPost.Get(TongQuatDoanhNghiep_PostID);
                    rptGioiThieu.DataBind();
                    rptProject.DataSource = _BPost.Get(DuAnTieuBieu_CatID, 3);
                    rptProject.DataBind();
                    rptNews.DataSource = _BPost.Get(TinTuc_CatID, 8);
                    rptNews.DataBind();
                    rptLink.DataSource = _BPost.Get(LienKet_PostID);
                    rptLink.DataBind();
                    rptHoatDong.DataSource = _BPost.Get(HoatDong_PostID);
                    rptHoatDong.DataBind();
                    rptPoll.DataSource = _BPoll.GetLastRecord();
                    rptPoll.DataBind();
                    rptBannerKhaoSat.DataSource = _BPost.Get(BannerKhaoSat_PostID);
                    rptBannerKhaoSat.DataBind();
                }
                else if (Session["LangID"].ToString() == "en-US")
                {
                    rptBanner.DataSource = _BPost.Get(Banner_PostID);
                    rptBanner.DataBind();
                    rptGioiThieu.DataSource = _BPost.Get(About_PostID);
                    rptGioiThieu.DataBind();
                    rptProject.DataSource = _BPost.Get(FeaturedProjects_CatID, 3);
                    rptProject.DataBind();
                    rptNews.DataSource = _BPost.Get(News_CatID, 8);
                    rptNews.DataBind();
                    rptLink.DataSource = _BPost.Get(Link_PostID);
                    rptLink.DataBind();
                    rptHoatDong.DataSource = _BPost.Get(HoatDong_PostID);
                    rptHoatDong.DataBind();
                    rptPoll.DataSource = _BPoll.GetLastRecord();
                    rptPoll.DataBind();
                    rptBannerKhaoSat.DataSource = _BPost.Get(BannerKhaoSat_PostID);
                    rptBannerKhaoSat.DataBind();
                }                
                LoadString(ci);                
                lblUserOnline.Text = Application["useronline"].ToString();
                lblVisit.Text = Application["count_visit"].ToString();
            }            
        }
        protected void LoadString(CultureInfo ci)
        {
            lblNewsHot.Text = rm.GetString("hotnews", ci);
            lblFeaturedProject.Text = rm.GetString("featuredproject", ci);            
            lblPool.Text = rm.GetString("pool", ci);
            lblCountOnline.Text = rm.GetString("useronline", ci);
            lblCountVisit.Text = rm.GetString("countvisit", ci);
            lblSubcrible.Text = rm.GetString("subcrible", ci);
            lblStatistic.Text = rm.GetString("statistic", ci);
            lblExchangeRete.Text = rm.GetString("exchangerate", ci);
            lblRate.Text = rm.GetString("exchangerate", ci);
            lblGold.Text = rm.GetString("gold", ci);
            lblGoldType.Text = rm.GetString("type", ci);
            lblSelling.Text = rm.GetString("selling", ci);
            lblBuying.Text = rm.GetString("buying", ci);
        }
        protected void btnSubcrible_Click(object sender, EventArgs e)
        {
            if (txtEmail.Text != "")
            {
                if (_BEmail.Add(txtEmail.Text))
                {
                    RegisterClientScriptBlock("NOTE", "<script>alert('Đăng ký nhận bản tin thành công.');</script>");
                    IList<OPost> lstOPost = _BPost.Get(int.Parse(ConfigurationManager.AppSettings["reply-email-subcrible"].ToString()));
                    string content = lstOPost[0].Content;
                    string subject = "[send-mail-EnmineKaitlin]-Đăng ký nhận bản tin thành công";
                    
                    SmtpSection cfg = (SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp");

                    List<string> lstSendTo = new List<string>();
                    lstSendTo.Add(txtEmail.Text.Trim());

                    Send_Email(cfg.Network.UserName, lstSendTo, subject, content);
                }
            }
        }
    }
}
